package com.kdl.webconfig.converter;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.google.common.collect.Lists;
import com.kdl.webconfig.entity.CustomInfo;
import com.kdl.webconfig.entity.News;
import com.kdl.webconfig.entity.PicConfig;
import com.kdl.webconfig.vo.config.CustomInfoVO;
import com.kdl.webconfig.vo.config.NewsVO;
import com.kdl.webconfig.vo.config.PicConfigVO;

import java.util.List;
import java.util.Objects;

/**
 * @author 王成杰
 * @description TODO
 * @date 2022-09-05 下午3:27
 */

public class VOConvert {
    
    public static List<PicConfigVO> parsePicVosByPojos(List<PicConfig> picConfigs){
        List<PicConfigVO> picConfigVOS = Lists.newArrayList();
        if(CollectionUtils.isNotEmpty(picConfigs)){
            for (PicConfig picConfig : picConfigs) {
                PicConfigVO picConfigVO = parsePicVoByPojo(picConfig);
                picConfigVOS.add(picConfigVO);
            }
        }
        return picConfigVOS;
    }

    private static PicConfigVO parsePicVoByPojo(PicConfig picConfig) {
        if(Objects.isNull(picConfig)){
            return null;
        }
        PicConfigVO picConfigVO = new PicConfigVO();
        picConfigVO.setId(picConfig.getId());
        picConfigVO.setPicUrl(picConfig.getPicUrl());
        picConfigVO.setTitle(picConfig.getTitle());
        picConfigVO.setComment(picConfig.getComment());
        picConfigVO.setState(picConfig.getState());
        picConfigVO.setSort(picConfig.getSort());
        picConfigVO.setType(picConfig.getType());
        picConfigVO.setCreateTime(picConfig.getCreateTime());
        picConfigVO.setUpdateTime(picConfig.getUpdateTime());
        return picConfigVO;
    }



    public static List<NewsVO> parseNewsVosByPojos(List<News> records) {
        List<NewsVO> newsVOS = Lists.newArrayList();
        for (News record : records) {
            NewsVO newsVO = parseNewsVOByPojo(record);
            newsVOS.add(newsVO);
        }
        return newsVOS;
    }

    public static NewsVO parseNewsVOByPojo(News news){
        if(Objects.isNull(news)){
            return null;
        }
        NewsVO newsVO = new NewsVO();
        newsVO.setId(news.getId());
        newsVO.setPicUrl(news.getPicUrl());
        newsVO.setState(news.getState());
        newsVO.setTitle(news.getTitle());
        newsVO.setPublishDate(news.getPublishTime());
        newsVO.setComment(news.getComment());
        newsVO.setLinkUrl(news.getLinkUrl());
        return newsVO;
    }

    public static List<CustomInfoVO> parseCustomInfoVOSByPojos(List<CustomInfo> customInfos){
        List<CustomInfoVO> customInfoVOS = Lists.newArrayList();
        for (CustomInfo customInfo : customInfos) {
            CustomInfoVO customInfoVO = new CustomInfoVO();
            customInfoVO.setCustomEmail(customInfo.getCustomEmail());
            customInfoVO.setCustomName(customInfo.getCustomName());
            customInfoVO.setCustomPhone(customInfo.getCustomPhone());
            customInfoVO.setMessage(customInfo.getMessage());
            customInfoVO.setId(customInfo.getId());
            customInfoVOS.add(customInfoVO);
        }
        return customInfoVOS;
    }

}
